package club.drguo.hadoop.mapreduce.topkurl;

import java.io.IOException;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class TopKeyURLMapper extends Mapper<LongWritable, Text, Text, FlowBean> {
	private FlowBean bean = new FlowBean();
	private Text k = new Text();

	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, FlowBean>.Context context)
			throws IOException, InterruptedException {
		String line = value.toString();
		String[] strings = StringUtils.split(line, "\t");
		try {
			if (strings.length > 32 && StringUtils.isNotEmpty(strings[26]) && strings[26].startsWith("http")) {
				String url = strings[26];
				long up_flow = Long.parseLong(strings[30]);
				long down_flow = Long.parseLong(strings[31]);
				k.set(url);
				System.out.println("+++++++++++"+up_flow);
				bean.set(up_flow, down_flow);
				context.write(k, bean);
//				System.out.println(url);
			}
		} catch (Exception e) {
			System.out.println("topkeyurlmapper有问题。。。。。");
		}
	}
}
